<template>
  <el-container v-loading="loading">

    <el-row>
      <el-button
        icon="fa fa-fw fa-refresh"
        size="mini"
        type="info"
        @click="handleRefresh">
      </el-button>
    </el-row>

    <el-table
      @selection-change="handleSelectionChange"
      :data="tableData"
      tooltip-effect="dark"
      border
      :default-sort="{prop: 'date', order: 'descending'}"
      :row-class-name="tableRowClassName"
    >
      <el-table-column
        prop="order_no"
        label="订单编号"
        width="200">
      </el-table-column>

      <el-table-column
        prop="uname"
        label="投诉人昵称"
        width="200">
      </el-table-column>

      <el-table-column
        prop="name"
        label="投诉人姓名"
        width="200">
      </el-table-column>

      <el-table-column
        prop="phone"
        label="投诉人手机号"
        width="200">
      </el-table-column>

      <el-table-column
        prop="dname"
        label="代驾人昵称"
        width="200">
      </el-table-column>

      <el-table-column
        prop="content"
        label="投诉内容">
      </el-table-column>

      <el-table-column
        prop="create_time"
        label="投诉时间"
        width="200">
        <template slot-scope="scope">
          <i class="fa fa-fw fa-clock-o"></i>
          <span style="margin-left: 10px">{{ scope.row.create_time }}</span>
        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagination.currentPage"
      :page-sizes="pagination.pageSizes"
      :page-size="pagination.pageSize"
      :total="pagination.total"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

  </el-container>
</template>

<script>
  export default {
    mounted: function () {
      this.getData();
    },
    methods: {
      /**
       * 数据请求
       * */
      getData: function () {
        let _this = this;
        this.api.getOrderComplaintList({
          page: this.pagination.currentPage,
          rows: this.pagination.pageSize,
        }).then(function (res) {
          if (res.code == 1) {
            _this.tableData = res.data.data;
            _this.pagination.total = res.data.total;
          }
          _this.loading = false;
        }).catch(function (res) {
          throw new Error(res);
        });
      },
      /**
       * 分页数改变
       */
      handleSizeChange: function (pageSize) {
        this.pagination.pageSize = pageSize;
        this.getData();
      },
      /**
       * 当前页面改变
       * @param currentPage
       */
      handleCurrentChange: function (currentPage) {
        this.pagination.currentPage = currentPage;
        this.getData();
      },
      tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row'
        } else if (rowIndex === 3) {
          return 'success-row'
        }
        return ''
      },
      /**
       * 数据刷新
       */
      handleRefresh: function () {
        this.getData();
        this.$message({
          showClose: true,
          message: '刷新成功',
          type: 'success'
        });
      },
      /**
       * 表格选中状态记录
       * @param val
       */
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      /**
       * 获取时间
       * @param type
       */
      getTimed: function () {
        const start = new Date();
        const end = new Date();
        let day = 0;
        if (this.constraintForm.timeType == '2') {
          day = 7;
        } else if (this.constraintForm.timeType == '3') {
          day = 30;
        } else if (this.constraintForm.timeType == '4') {
          day = 90;
        }
        if (this.constraintForm.timeType == '2' || this.constraintForm.timeType == '3' || this.constraintForm.timeType == '4') {
          start.setTime(start.getTime() - 3600 * 1000 * 24 * day);
          let timeArr = [];
          timeArr.push(start.getTime());
          timeArr.push(end.getTime());
          this.constraintForm.time = timeArr;
        } else if (this.constraintForm.timeType == '1' || this.constraintForm.timeType == '5') {
          this.constraintForm.time = [];
        }
      },
      /**
       * 条件数据检索
       */
      constraintSearchData: function () {
        this.getData();
        this.$message({
          showClose: true,
          message: '查询成功',
          type: 'success'
        });
      },
      /**
       * 远程数据加载
       */
      querySearchAsync(queryString, cb) {
        let _this = this;
        this.api.searchRunnerByUserName({name: queryString}).then(function (res) {
          if (res.code == '1') {
            cb(res.data.data);
          }
        }).catch(function (res) {
          throw new Error(res);
        });
      },
      /**
       * 搜索下拉选择
       * @param item
       */
      handleSelect(item) {
        this.constraintForm.text = item.name;
        this.constraintForm.id = item.id;
      },
    },
    data() {
      return {
        loading: true,  // 页面加载
        tableData: [
        ],
        multipleSelection: [],
        pagination: {
          total: 5,
          currentPage: 1,
          pageSize: 10,
          pageSizes: [5, 10, 20, 25, 30, 50, 100],
        },
        constraintForm: {
          star: '',    // 1,2,3,4,5，默认''
          timeType: '1',   // 时间类型 1=>不限 2=>近一周 3=>近一月 4=>近三月 5=>自定义
          time: [],    // 时间戳，中横线分割‘-’,默认0
          text: '',    // 检索姓名，默认''
          id: '',    // 用户id，默认0
        }
      }
    },
  }
</script>

<style scoped>
  .el-container {
    display: block;
  }

  .el-table, .el-row {
    width: 98% !important;
    margin: 15px auto;
  }

  .el-pagination {
    text-align: center;
    margin: 15px 0;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }

  .logo-img {
    width: 40px;
    height: 40px;
  }

  .el-date-picker {
    top: -3px;
    margin: 0 0 0 15px;
  }
</style>
